package com.grape.api.v1.controller;

import cn.hutool.core.collection.CollectionUtil;
import com.github.pagehelper.PageInfo;
import com.grape.annotation.OperateMethodName;
import com.grape.annotation.RepeatSubmit;
import com.grape.controller.BaseController;
import com.grape.result.R;
import com.grape.vo.BaseVo;
import com.grape.vo.MemberOpenVO;
import com.grape.domain.Member;
import com.grape.service.IMemberService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 会员表 控制器
 * @author      putao
 * @email       2628279194@qq.com
 */
@RestController
@RequestMapping("members")
@Api(tags = "会员接口")
@AllArgsConstructor
public class MemberController extends BaseController<Member> {

    private final IMemberService memberService;


    @GetMapping
    @ApiOperation(value = "会员分页")
    @OperateMethodName(value = "会员表列表分页", url = "member:members:listPage")
    public R<?> listPage(BaseVo baseVo) {
        PageInfo<Member> pageInfo = memberService.pageList(baseVo);
        List<Member> memberList = pageInfo.getList();
        return CollectionUtil.isNotEmpty(memberList) ? selectSuccess(pageInfo, baseVo) : selectNotFound(pageInfo, baseVo);
    }


    @RepeatSubmit
    @PostMapping
    @ApiOperation(value = "添加会员")
    @OperateMethodName(value = "添加会员表", url = "member:members:insert")
    public R<?> insert(@Validated @RequestBody MemberOpenVO memberOpenVO) {
        return insertSuccess(memberService.insertData(memberOpenVO), null);
    }
}

